﻿<%@ Control Language="C#" ClassName="LeftMain" %>
<%--<%@ OutputCache VaryByParam="None" Duration="10" %>--%>

<script runat="server">
  
  protected void Page_Load(object sender, EventArgs e)
  {
    if (!Page.IsPostBack)
    {
      B2C_MALL_Categories ws = new B2C_MALL_Categories();
      ws.Url = ConfigurationManager.AppSettings["B2C_MALL_Categories"].ToString();
      string jsonString =
        ws.B2C_MALL_GetCategories(ConfigurationManager.AppSettings["WebDeviceid"].ToString()
        , HttpContext.Current.User.Identity.Name);
      JObject restoredObject = JsonConvert.DeserializeObject<JObject>(jsonString);
      var q = from j in restoredObject.Properties()
              select j;
      JObject jo = new JObject();
      string Is_Valid = restoredObject["Is_Valid"].ToString();
      string msg = restoredObject["Msg"].ToString();
      if (Is_Valid == "Y")
      {
        JArray jArray = (JArray)restoredObject["PROD_CAT_Ary"];
        Session["JArray"] = jArray;
        dynamic dynObj = jArray.OrderBy(c => c["parent_id"]).OrderBy(x => x["PROD_CAT_ID"]);
        //var newlist = jArray.OrderByDescending(x => x["PROD_CAT_ID"]).ToArray();

        var menu1 = jArray.Where(m => m["parent_id"].ToString() == "1").OrderBy(x => x["PROD_CAT_ID"]);
        if (menu1.Count() == 0) dropdown1.Visible = false;
        ListRepeater1.DataSource = menu1;
        ListRepeater1.DataBind();

        var menu2 = jArray.Where(m => m["parent_id"].ToString() == "2").OrderBy(x => x["PROD_CAT_ID"]);
        if (menu2.Count() == 0) dropdown2.Visible = false;
        ListRepeater2.DataSource = menu2;
        ListRepeater2.DataBind();

        var menu3 = jArray.Where(m => m["parent_id"].ToString() == "3").OrderBy(x => x["PROD_CAT_ID"]);
        if (menu3.Count() == 0) dropdown3.Visible = false;
        ListRepeater3.DataSource = menu3;
        ListRepeater3.DataBind();

        var menu4 = jArray.Where(m => m["parent_id"].ToString() == "4").OrderBy(x => x["PROD_CAT_ID"]);
        if (menu4.Count() == 0) dropdown4.Visible = false;
        ListRepeater4.DataSource = menu4;
        ListRepeater4.DataBind();

        var menu5 = jArray.Where(m => m["parent_id"].ToString() == "5").OrderBy(x => x["PROD_CAT_ID"]);
        if (menu5.Count() == 0) dropdown5.Visible = false;
        ListRepeater5.DataSource = menu5;
        ListRepeater5.DataBind();

        var menu6 = jArray.Where(m => m["parent_id"].ToString() == "6").OrderBy(x => x["PROD_CAT_ID"]);
        if (menu6.Count() == 0) dropdown6.Visible = false;
        ListRepeater6.DataSource = menu6;
        ListRepeater6.DataBind();

        var menu7 = jArray.Where(m => m["parent_id"].ToString() == "7").OrderBy(x => x["PROD_CAT_ID"]);
        if (menu7.Count() == 0) dropdown7.Visible = false;
        ListRepeater7.DataSource = menu7;
        ListRepeater7.DataBind();


        var menu8 = jArray.Where(m => m["parent_id"].ToString() == "8").OrderBy(x => x["PROD_CAT_ID"]);
        if (menu8.Count() == 0) dropdown8.Visible = false;
        ListRepeater8.DataSource = menu8;
        ListRepeater8.DataBind();
       
      }
      else
      {
        //錯誤處理
      }

      //暢銷排行榜
      GetRateProductList();
    }
  }

  string RedGreen = ConfigurationManager.AppSettings["RedGreen"].ToString();
  string Clock = ConfigurationManager.AppSettings["Clock"].ToString();
  string Period = ConfigurationManager.AppSettings["Period"].ToString();  
  
  protected void ListRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
  {
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
      Repeater rep = e.Item.FindControl("childRepeater") as Repeater;
      Label lbl_PROD_CAT_ID = e.Item.FindControl("lbl_PROD_CAT_ID") as Label;      
      if (rep != null)
      {
        dynamic dynObj = (Session["JArray"] as JArray)
          .Where(m => m["parent_id"].ToString() == lbl_PROD_CAT_ID.Text)
          .OrderBy(x => x["PROD_CAT_ID"]);
        rep.DataSource = dynObj;
        rep.DataBind();
      }

      HtmlAnchor A1 = e.Item.FindControl("A1") as HtmlAnchor;      
      if (lbl_PROD_CAT_ID.Text == RedGreen)
      {
        A1.HRef = "~/Products/ProductsListRedGreen.aspx";
      }
      else if (lbl_PROD_CAT_ID.Text == Clock)
      {
        A1.HRef = "~/Products/ProductsListClock.aspx?category=" 
          + System.Configuration.ConfigurationManager.AppSettings["Clock"].ToString();
      }
      else if (lbl_PROD_CAT_ID.Text == Period)
      {
        A1.HRef = "~/Products/ProductsListPeriod.aspx?category="
          + System.Configuration.ConfigurationManager.AppSettings["Period"].ToString();
      }     
    }
  }

  protected void GetRateProductList()
  {
    B2C_MALL_HOME ws = new B2C_MALL_HOME();
    ws.Url = ConfigurationManager.AppSettings["B2C_MALL_HOME"].ToString();
    //暢銷排行榜：0
    string jsonString = 
      ws.B2C_MALL_getBoards(ConfigurationManager.AppSettings["WebDeviceid"].ToString() 
      , HttpContext.Current.User.Identity.Name, "0");
    JObject restoredObject = JsonConvert.DeserializeObject<JObject>(jsonString);
    if (restoredObject != null)
    {
      string Is_Valid = restoredObject["Is_Valid"].ToString();
      string msg = restoredObject["Msg"].ToString();

      if (Is_Valid == "Y")
      {
        dynamic dynObj = restoredObject["Prd_Ary"];
        ListViewPromotions.DataSource = dynObj;
        ListViewPromotions.DataBind();
      }
    } 
  }

</script>

<!--#Menu-->
<div class="navigation JS-navigation">
  <ul>
    <asp:Literal ID="MenuText" runat="server" Mode="PassThrough"></asp:Literal>
    <li>
      <a href="~/Products/ProductsList.aspx?category=1" runat="server">長榮獨家</a>
      <div class="dropdown" id="dropdown1" runat="server">
        <div class="drop-left">
          <asp:Repeater runat="server" ID="ListRepeater1" OnItemDataBound="ListRepeater_ItemDataBound">
            <ItemTemplate>
              <ul>
                <li><a id="A1" href='<%# "~/Products/ProductsList.aspx?category=" + Server.HtmlEncode(Eval("PROD_CAT_ID").ToString()) %>' runat="server">
                  <asp:Literal ID="ListLiteral" runat="server" Text='<%# Server.HtmlEncode(Eval("PROD_CAT_TYPE").ToString()) %>' /></a>
                  <asp:Label ID="lbl_PROD_CAT_ID" runat="server" Text='<%# Server.HtmlEncode(Eval("PROD_CAT_ID").ToString()) %>' Visible="false" />
                  <ul>
                    <asp:Repeater runat="server" ID="childRepeater">
                      <ItemTemplate>

                        <li><a id="A2" href='<%# "~/Products/ProductsList.aspx?category=" + Server.HtmlEncode(Eval("PROD_CAT_ID").ToString()) %>' runat="server">
                          <asp:Literal ID="childLiteral" runat="server" Text='<%# Server.HtmlEncode(Eval("PROD_CAT_TYPE").ToString()) %>' /></a></li>
                      </ItemTemplate>
                    </asp:Repeater>
                  </ul>
                </li>
              </ul>
            </ItemTemplate>
          </asp:Repeater>

        </div>

      </div>
    </li>
    <li>
      <a href="~/Products/ProductsList.aspx?category=2" runat="server">寰宇精品</a>
      <div class="dropdown" id="dropdown2" runat="server">
        <div class="drop-left">
          <asp:Repeater runat="server" ID="ListRepeater2" OnItemDataBound="ListRepeater_ItemDataBound">
            <ItemTemplate>
              <ul>
                <li><a id="A1" href='<%# "~/Products/ProductsList.aspx?category=" + Server.HtmlEncode(Eval("PROD_CAT_ID").ToString()) %>' runat="server">
                  <asp:Literal ID="ListLiteral" runat="server" Text='<%# Server.HtmlEncode(Eval("PROD_CAT_TYPE").ToString()) %>' /></a>
                  <asp:Label ID="lbl_PROD_CAT_ID" runat="server" Text='<%# Server.HtmlEncode(Eval("PROD_CAT_ID").ToString()) %>' Visible="false" />
                  <ul>
                    <asp:Repeater runat="server" ID="childRepeater">
                      <ItemTemplate>

                        <li><a id="A2" href='<%# "~/Products/ProductsList.aspx?category=" + Server.HtmlEncode(Eval("PROD_CAT_ID").ToString()) %>' runat="server">
                          <asp:Literal ID="childLiteral" runat="server" Text='<%# Server.HtmlEncode(Eval("PROD_CAT_TYPE").ToString()) %>' /></a></li>

                      </ItemTemplate>
                    </asp:Repeater>
                  </ul>
                </li>
              </ul>
            </ItemTemplate>
          </asp:Repeater>

        </div>
      </div>
    </li>
    <li>
      <a href="~/Products/ProductsList.aspx?category=3" runat="server">消費電子</a>
      <div class="dropdown" id="dropdown3" runat="server">
        <div class="drop-left">

          <asp:Repeater runat="server" ID="ListRepeater3" OnItemDataBound="ListRepeater_ItemDataBound">
            <ItemTemplate>
              <ul>
                <li><a id="A1" href='<%# "~/Products/ProductsList.aspx?category=" + Server.HtmlEncode(Eval("PROD_CAT_ID").ToString()) %>' runat="server">
                  <asp:Literal ID="ListLiteral" runat="server" Text='<%# Server.HtmlEncode(Eval("PROD_CAT_TYPE").ToString()) %>' /></a>
                  <asp:Label ID="lbl_PROD_CAT_ID" runat="server" Text='<%# Server.HtmlEncode(Eval("PROD_CAT_ID").ToString()) %>' Visible="false" />
                  <ul>
                    <asp:Repeater runat="server" ID="childRepeater">
                      <ItemTemplate>

                        <li><a id="A2" href='<%# "~/Products/ProductsList.aspx?category=" + Server.HtmlEncode(Eval("PROD_CAT_ID").ToString()) %>' runat="server">
                          <asp:Literal ID="childLiteral" runat="server" Text='<%# Server.HtmlEncode(Eval("PROD_CAT_TYPE").ToString()) %>' /></a></li>

                      </ItemTemplate>
                    </asp:Repeater>
                  </ul>
                </li>
              </ul>
            </ItemTemplate>
          </asp:Repeater>

        </div>

      </div>
    </li>
    <li>
      <a href="~/Products/ProductsList.aspx?category=4" runat="server">居家生活</a>
      <div class="dropdown" id="dropdown4" runat="server">
        <div class="drop-left">

          <asp:Repeater runat="server" ID="ListRepeater4" OnItemDataBound="ListRepeater_ItemDataBound">
            <ItemTemplate>
              <ul>
                <li><a id="A1" href='<%# "~/Products/ProductsList.aspx?category=" + Server.HtmlEncode(Eval("PROD_CAT_ID").ToString()) %>' runat="server">
                  <asp:Literal ID="ListLiteral" runat="server" Text='<%# Server.HtmlEncode(Eval("PROD_CAT_TYPE").ToString()) %>' /></a>
                  <asp:Label ID="lbl_PROD_CAT_ID" runat="server" Text='<%# Server.HtmlEncode(Eval("PROD_CAT_ID").ToString()) %>' Visible="false" />
                  <ul>
                    <asp:Repeater runat="server" ID="childRepeater">
                      <ItemTemplate>

                        <li><a id="A2" href='<%# "~/Products/ProductsList.aspx?category=" + Server.HtmlEncode(Eval("PROD_CAT_ID").ToString()) %>' runat="server">
                          <asp:Literal ID="childLiteral" runat="server" Text='<%# Server.HtmlEncode(Eval("PROD_CAT_TYPE").ToString()) %>' /></a></li>

                      </ItemTemplate>
                    </asp:Repeater>
                  </ul>
                </li>
              </ul>
            </ItemTemplate>
          </asp:Repeater>

        </div>

      </div>
    </li>
    <li>
      <a href="~/Products/ProductsList.aspx?category=5" runat="server">美容保健</a>
      <div class="dropdown" id="dropdown5" runat="server">
        <div class="drop-left">

          <asp:Repeater runat="server" ID="ListRepeater5" OnItemDataBound="ListRepeater_ItemDataBound">
            <ItemTemplate>
              <ul>
                <li><a id="A1" href='<%# "~/Products/ProductsList.aspx?category=" + Server.HtmlEncode(Eval("PROD_CAT_ID").ToString()) %>' runat="server">
                  <asp:Literal ID="ListLiteral" runat="server" Text='<%# Server.HtmlEncode(Eval("PROD_CAT_TYPE").ToString()) %>' /></a>
                  <asp:Label ID="lbl_PROD_CAT_ID" runat="server" Text='<%# Server.HtmlEncode(Eval("PROD_CAT_ID").ToString()) %>' Visible="false" />
                  <ul>
                    <asp:Repeater runat="server" ID="childRepeater">
                      <ItemTemplate>

                        <li><a id="A2" href='<%# "~/Products/ProductsList.aspx?category=" + Server.HtmlEncode(Eval("PROD_CAT_ID").ToString()) %>' runat="server">
                          <asp:Literal ID="childLiteral" runat="server" Text='<%# Server.HtmlEncode(Eval("PROD_CAT_TYPE").ToString()) %>' /></a></li>

                      </ItemTemplate>
                    </asp:Repeater>
                  </ul>
                </li>
              </ul>
            </ItemTemplate>
          </asp:Repeater>

        </div>

      </div>
    </li>
    <li>
      <a href="~/Products/ProductsList.aspx?category=6" runat="server">美食饗宴</a>
      <div class="dropdown" id="dropdown6" runat="server">
        <div class="drop-left">

          <asp:Repeater runat="server" ID="ListRepeater6" OnItemDataBound="ListRepeater_ItemDataBound">
            <ItemTemplate>
              <ul>
                <li><a id="A1" href='<%# "~/Products/ProductsList.aspx?category=" + Server.HtmlEncode(Eval("PROD_CAT_ID").ToString()) %>' runat="server">
                  <asp:Literal ID="ListLiteral" runat="server" Text='<%# Server.HtmlEncode(Eval("PROD_CAT_TYPE").ToString()) %>' /></a>
                  <asp:Label ID="lbl_PROD_CAT_ID" runat="server" Text='<%# Server.HtmlEncode(Eval("PROD_CAT_ID").ToString()) %>' Visible="false" />
                  <ul>
                    <asp:Repeater runat="server" ID="childRepeater">
                      <ItemTemplate>

                        <li><a id="A2" href='<%# "~/Products/ProductsList.aspx?category=" + Server.HtmlEncode(Eval("PROD_CAT_ID").ToString()) %>' runat="server">
                          <asp:Literal ID="childLiteral" runat="server" Text='<%# Server.HtmlEncode(Eval("PROD_CAT_TYPE").ToString()) %>' /></a></li>

                      </ItemTemplate>
                    </asp:Repeater>
                  </ul>
                </li>
              </ul>
            </ItemTemplate>
          </asp:Repeater>

        </div>

      </div>
    </li>
    <li>
      <a href="~/Products/ProductsListMileages.aspx?category=7" runat="server">哩上加禮</a>
      <div class="dropdown" id="dropdown7" runat="server">
        <div class="drop-left">

          <asp:Repeater runat="server" ID="ListRepeater7" OnItemDataBound="ListRepeater_ItemDataBound">
            <ItemTemplate>
              <ul>
                <li><a id="A1" href='<%# "~/Products/ProductsListMileages.aspx?category=" + Server.HtmlEncode(Eval("PROD_CAT_ID").ToString()) %>' runat="server">
                  <asp:Literal ID="ListLiteral" runat="server" Text='<%# Server.HtmlEncode(Eval("PROD_CAT_TYPE").ToString()) %>' /></a>
                  <asp:Label ID="lbl_PROD_CAT_ID" runat="server" Text='<%# Server.HtmlEncode(Eval("PROD_CAT_ID").ToString()) %>' Visible="false" />
                  <ul>
                    <asp:Repeater runat="server" ID="childRepeater">
                      <ItemTemplate>

                        <li><a id="A2" href='<%# "~/Products/ProductsListMileages.aspx?category=" + Server.HtmlEncode(Eval("PROD_CAT_ID").ToString()) %>' runat="server">
                          <asp:Literal ID="childLiteral" runat="server" Text='<%# Server.HtmlEncode(Eval("PROD_CAT_TYPE").ToString()) %>' /></a></li>

                      </ItemTemplate>
                    </asp:Repeater>
                  </ul>
                </li>
              </ul>
            </ItemTemplate>
          </asp:Repeater>

        </div>

      </div>
    </li>
    <li>
      <a id="A3" runat="server">優惠情報</a>
      <div class="dropdown" id="dropdown8" runat="server">       
        <div class="drop-left">
          <asp:Repeater runat="server" ID="ListRepeater8" OnItemDataBound="ListRepeater_ItemDataBound">
            <ItemTemplate>
              <ul>
                <li><a id="A1" runat="server">
                  <asp:Literal ID="ListLiteral" runat="server" Text='<%# Server.HtmlEncode(Eval("PROD_CAT_TYPE").ToString()) %>' /></a>
                  <asp:Label ID="lbl_PROD_CAT_ID" runat="server" Text='<%# Server.HtmlEncode(Eval("PROD_CAT_ID").ToString()) %>' Visible="false" />
                  <asp:Repeater runat="server" ID="childRepeater">
                    <ItemTemplate>
                      <ul>
                        <li>
                          <a id="A2" runat="server">
                            <asp:Literal ID="childLiteral" runat="server" Text='<%# Server.HtmlEncode(Eval("PROD_CAT_TYPE").ToString()) %>' />
                          </a>
                        </li>
                      </ul>
                    </ItemTemplate>
                  </asp:Repeater>
                </li>
              </ul>
            </ItemTemplate>
          </asp:Repeater>
        </div>
      </div>
    </li>
  </ul>
</div>
<!--#Navigation-->
<div class="quick-links">
  <table>
    <tr>
      <td><a href="javascript:favority('樂e購', 'http://mall.evaair.com')">
        <img src="~/Images/QuickLinks/Favorite.png" id="Favorite" alt="加到我的最愛" runat="server" />
        <span>加到我的最愛</span>
      </a></td>
      <td>
        <a href="~/SiteMap.aspx" runat="server" id="HyperLink1">
          <img src="~/Images/QuickLinks/SiteMap.png" id="SiteMap" alt="網站導覽" runat="server" />
          <span>網站導覽</span>
        </a>
      </td>
    </tr>
    <tr>
      <td>
        <a href="javascript:ShowMemberPopup('1');" id="MyAccount" runat="server">
          <img src="~/Images/QuickLinks/MyAccount.png" id="Img2" alt="我的樂e購帳戶" runat="server" />
          <span>我的樂e購帳戶</span>
        </a>
      </td>
      <td>
        <a href="~/Shopping/ShoppingInformation.aspx" runat="server" id="HyperLink3">
          <img src="~/Images/QuickLinks/Information.png" id="Information" alt="購物須知" runat="server" />
          <span>購物須知</span>
        </a>
      </td>
    </tr>
  </table>

</div>
<!--#Quick-Links-->
<div class="left-promotions">
  <div class="item JS-slider">
    <h5>暢銷排行榜</h5>
    <div class="image-container">
      <asp:ListView ID="ListViewPromotions" runat="server">
        <ItemTemplate>
          <a id="A4" href='<%# Server.HtmlEncode(Eval("B2C_CODE","~/Products/ProductDetail.aspx?B2C_CODE={0}").ToString()) %>' runat="server">
            <img id="Img1" src='<%# Server.HtmlEncode(Eval("IMAGE_PATH_M").ToString()) %>' runat="server" />
            <div class="desc">
              <div class="desc-top">
                特價 $ <strong><%# Server.HtmlEncode(Eval("ACT_PRICE","{0:n0}").ToString()) %></strong>
              </div>
            </div>
            <div class="release">
              <%# CommonUtil.GetNEWAndHOT(Server.HtmlEncode(Eval("light_status").ToString())) %>
            </div>
          </a>
        </ItemTemplate>
      </asp:ListView>      
    </div>
  </div>
</div>
<!--#Left-promotions-->
<div class="new-products-nav">
  <h4>各館新品</h4>
  <ul>
    <li>
      <asp:HyperLink ID="HyperLink4" runat="server" NavigateUrl="~/Products/ProductsList.aspx?NewCatID=6">長榮獨家</asp:HyperLink></li>
    <li>
      <asp:HyperLink ID="HyperLink5" runat="server" NavigateUrl="~/Products/ProductsList.aspx?NewCatID=7">寰宇精品</asp:HyperLink></li>
    <li>
      <asp:HyperLink ID="HyperLink6" runat="server" NavigateUrl="~/Products/ProductsList.aspx?NewCatID=8">消費電子</asp:HyperLink></li>
    <li>
      <asp:HyperLink ID="HyperLink7" runat="server" NavigateUrl="~/Products/ProductsList.aspx?NewCatID=9">居家生活</asp:HyperLink></li>
    <li>
      <asp:HyperLink ID="HyperLink8" runat="server" NavigateUrl="~/Products/ProductsList.aspx?NewCatID=10">美容保健</asp:HyperLink></li>
    <li>
      <asp:HyperLink ID="HyperLink9" runat="server" NavigateUrl="~/Products/ProductsList.aspx?NewCatID=11">美食饗宴</asp:HyperLink></li>
    <li>
      <asp:HyperLink ID="HyperLink10" runat="server" NavigateUrl="~/Products/ProductsListMileages.aspx?NewCatID=12">哩上加禮</asp:HyperLink></li>
    <li>
      <asp:HyperLink ID="HyperLink11" runat="server" NavigateUrl="~/Products/ProductsList.aspx?NewCatID=13">優惠情報</asp:HyperLink></li>
  </ul>
</div>


